package com.action.music;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.business.music.MusicListBus;
import com.business.music.MusicTypeBus;
import com.config.SystemGlobals;

public class UpdateMusicType extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
		String action = request.getParameter("action");
		String typeId = request.getParameter("id");
		if ("del".equals(action)) {
			MusicListBus mlb=new MusicListBus();
			if(mlb.getAllMusicByTypeID(Integer.parseInt(typeId)).size()==0){
			MusicTypeBus mtb = new MusicTypeBus();
			mtb.del(typeId);
			out.println("<script>alert(\"删除音乐分类成功\");window.location=\"user/musiclist.jsp\";</script>");
			}		
			else{
			out.println("<script>alert(\"对不起,此分类下还有音乐,不能删除\");window.location=\"user/musiclist.jsp\";</script>");
		}
			}
		
		if ("edit".equals(action)) {
			RequestDispatcher rd = request
					.getRequestDispatcher("/user/editmusictype.jsp?id="
							+ typeId);
			rd.forward(request, response);
		}
	}

}
